<%@ page language="java" import="java.util.*,com.knife.member.*,java.sql.Timestamp" pageEncoding="UTF-8"%>
<%@include file="../inc/checkuser.jsp" %><%
request.setCharacterEncoding("UTF-8");
String msg="";
String docid="";
int type=0;
if(request.getParameter("docid")!=null){
	docid = request.getParameter("docid");
}
if(request.getParameter("type")!=null){
	type = Integer.parseInt(request.getParameter("type"));
}
UserfavDAO uvDAO=new UserfavDAO();
Userfav uv=new Userfav();
if(docid.length()>0){
	List users = userDAO.findByEmail(login_email);
	if(users.size()>0){
		Userinfo loginUser = (Userinfo)users.get(0);
		List favs = uvDAO.findByUseridAndDocid(loginUser.getId().intValue(),docid);
		if(favs.size()>0){
			msg="资料已添加，请不要重复添加！";
		}else{
			uv.setUserid(loginUser.getId().intValue());
			uv.setDocid(docid);
			uv.setType(type);
			try{ 
				Timestamp applyTime = new Timestamp((new Date()).getTime());
				uv.setFavdate(applyTime);
			}catch(Exception e){
				//e.printStackTrace();
			}
			try{
				uvDAO.save(uv);
				msg="添加成功！";
			}catch(Exception e){
				msg="添加失败！";
			}
		}
	}
}
%><%=msg%>